package com.coding.kan_yi_dao.common;

import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private T data;
    private String msg;

    public static Result ok(String msg) {
        Result result = new Result();
        result.setCode(200);
        result.setMsg(msg);
        return result;
    }

    public static <T> Result ok(T data) {
        Result result = new Result();
        result.setCode(200);
        result.setData(data);
        return result;
    }

    public static <T> Result ok(String msg, T data) {
        Result result = new Result();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result fail(String msg) {
        Result result = new Result();
        result.setCode(0);
        result.setMsg(msg);
        return result;
    }

    public static <T> Result fail(T data) {
        Result result = new Result();
        result.setCode(0);
        result.setData(data);
        return result;
    }

    public static <T> Result fail(String msg, T data) {
        Result result = new Result();
        result.setCode(0);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
}
